package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.request.DispatchKeepWatchPersonReq;
import net.hn.hnms.biz.plan.service.IDispatchKeepWatchPersonService;
import net.hn.hnms.biz.plan.vo.DispatchKeepWatchPersonVO;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 带值班人员
 *
 * @author zhaoyang
 * @date 2022-08-01
 */

@Api(value = "带值班人员模块", tags = {"带值班人员"})
@RestController
@RequestMapping("/dispatch/person")
public class DispatchKeepWatchPersonController extends BaseController {


    @Autowired
    private IDispatchKeepWatchPersonService dispatchKeepWatchPersonService;


    /**
     * 新增带值班人员
     */
    @ApiOperation("新增带值班人员")
    @SaCheckPermission("dispatch:keepwatch:person:add")
    @PostMapping("/add")
    @Log(title = "新增带值班人员", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody DispatchKeepWatchPersonReq dispatchKeepWatchPerson) {
        return toAjax(dispatchKeepWatchPersonService.insert(dispatchKeepWatchPerson));
    }

    /**
     * 删除带值班人员
     */
    @ApiOperation("删除带值班人员")
    @SaCheckPermission("dispatch:keepwatch:person:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除带值班人员", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        dispatchKeepWatchPersonService.deleteBatch(idList);
        return R.ok();
    }

    /**
     * 修改带值班人员
     */
    @ApiOperation("修改带值班人员")
    @SaCheckPermission("dispatch:keepwatch:person:update")
    @PutMapping("/update")
    @Log(title = "修改带值班人员", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody DispatchKeepWatchPersonReq dispatchKeepWatchPerson) {
        dispatchKeepWatchPersonService.updateById(dispatchKeepWatchPerson);
        return R.ok();
    }

    /**
     * 启用/禁用
     */
    @ApiOperation("启用/禁用")
    @SaCheckPermission("dispatch:keepwatch:person:status:change")
    @PutMapping("/status/change/{id}/{status}")
    @Log(title = "班启用/禁用", businessType = BusinessType.GRANT)
    public R<Void> changeStatus(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        dispatchKeepWatchPersonService.changeStatus(id, status);
        return R.ok();
    }

    /**
     * 获取带值班人员列表
     */
    @ApiOperation("获取带值班人员分页列表")
//    @SaCheckPermission("dispatch:keepwatch:person:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<DispatchKeepWatchPersonVO>> page(DispatchKeepWatchPersonReq dispatchKeepWatchPerson, PageQuery pageQuery) {
        return R.ok(dispatchKeepWatchPersonService.selectPageList(dispatchKeepWatchPerson, pageQuery));
    }

    /**
     * 获取带值班人员列表
     */
    @ApiOperation("获取带值班人员列表")
//    @SaCheckPermission("dispatch:keepwatch:person:list")
    @GetMapping("/list")
    @AutoSetMineCode
    public R<List<DispatchKeepWatchPersonVO>> list(DispatchKeepWatchPersonReq dispatchKeepWatchPerson) {
        return R.ok(dispatchKeepWatchPersonService.selectList(dispatchKeepWatchPerson));
    }

    /**
     * 获取带值班人员详情
     */
    @ApiOperation("获取带值班人员详情")
//    @SaCheckPermission("dispatch:keepwatch:person:detail")
    @GetMapping("/{id}")
    public R<DispatchKeepWatchPersonVO> detail(@PathVariable("id") String id) {
        return R.ok(dispatchKeepWatchPersonService.selectDetailById(id));
    }

    @ApiOperation("获取岗位")
//    @SaCheckPermission("dispatch:keepwatch:person:detail")
    @GetMapping("/getPostType")
    public R<List<DispatchKeepWatchPersonVO>> getPostType() {
        return R.ok(dispatchKeepWatchPersonService.selectPostType());
    }

}
